package date0702pm;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import cn.edu.ecut.util.DatabaseType;
import cn.edu.ecut.util.JdbcHelper;

public class JdbcTest12 {

	public static void main(String[] args) throws SQLException {

		JdbcHelper h = JdbcHelper.getInstance( DatabaseType.ORACLE );
		
		String select = "SELECT id , name , gender , birthdate FROM t_students WHERE id = ? " ;
		// PreparedStatement 接口 继承了 Statement 接口
		PreparedStatement ps = h.prepare( select );
		System.out.println( ps );
		
		ps.setInt( 1 ,  1 );
		ResultSet rs = ps.executeQuery();
		System.out.println( "result set : " + rs );
		while( rs.next() ) { // if( rs.next() ) {
			System.out.print( rs.getInt( "id" ) + "\t" );
			System.out.print( rs.getString( "name" ) + "\t" );
			System.out.print( rs.getString( "gender" ) + "\t" );
			System.out.println( rs.getDate( "birthdate" ) );
		}
		h.close( rs );
		
		ps.setInt( 1 ,  2 );
		rs = ps.executeQuery();
		System.out.println( "result set : " + rs );
		while( rs.next() ) { // if( rs.next() ) {
			System.out.print( rs.getInt( "id" ) + "\t" );
			System.out.print( rs.getString( "name" ) + "\t" );
			System.out.print( rs.getString( "gender" ) + "\t" );
			System.out.println( rs.getDate( "birthdate" ) );
		}
		h.close( rs );
		
		
		h.close( ps );
		h.release();

	}

}
